package com.baoyouqun.controller.back;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.UserPointsRecordCreateCmd;
import com.baoyouqun.domain.Query.UserPointsRecordQuery;
import com.baoyouqun.domain.UpdateCmd.UserPointsRecordUpdateCmd;
import com.baoyouqun.domain.VO.UserPointsRecordVO;
import com.baoyouqun.service.UserPointsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/back/userPointsRecord")
@Api(tags = "用户积分变动记录表管理接口")
public class UserPointsRecordController {

    @Resource
    private UserPointsRecordService userPointsRecordService;

    @PostMapping("create")
    @ApiOperation("新增用户积分变动记录表")
    public SingleResponse<UserPointsRecordVO> create(UserPointsRecordCreateCmd cmd) {
        return userPointsRecordService.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改用户积分变动记录表")
    public Response update(@Valid @RequestBody UserPointsRecordUpdateCmd cmd) {
        return userPointsRecordService.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除用户积分变动记录表")
    public Response delete(String id) {
        StpUtil.checkRole("R010000");
        userPointsRecordService.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询用户积分变动记录表")
    public SingleResponse<UserPointsRecordVO> selectById(String id) {
        return SingleResponse.of(userPointsRecordService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询用户积分变动记录表")
    public PageResponse<UserPointsRecordVO> page(UserPointsRecordQuery query) {
        IPage<UserPointsRecordVO> page = userPointsRecordService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}